<!DOCTYPE html>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Travian辅助</title>
	<meta name="keywords" content="淮阳网站建设|周口网站建设">
	<meta name="description" content="淮阳网站建设|周口网站建设">
    <meta content="telephone=no" name="format-detection">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="renderer" content="webkit"><!--双引擎浏览器默认webkit打开-->
	<meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=no">
	<meta name="full-screen" content="yes">
	<link rel="stylesheet" href="__PUBLIC__/css/xcConfirm.css">
	<link rel="stylesheet" href="__PUBLIC__/css/uikit1.css">
	<script type="text/javascript" src="__PUBLIC__/js/jquery.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/xcConfirm.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/uikit.js"></script>
	
	<style>
	body{ padding:10px;}
	.active{color:#e4392a; border-bottom:3px solid #e4392a;}
	#my-id{ min-height:720px; line-height:1.8em;}
	#msg1,#msg1{ width:50%}
	#my-id li{word-wrap:break-word; word-break:normal; }
	.task{ width:600px; height:160px;}
	#bing1 .popBox{
    width: 570px;
    height: 500px;
    margin-left: -285px;
    margin-top: -250px;
	}
	#bing1 .popBox .txtBox{ height:200px;}
	#bing1 .text{ width:50px;}
	#bing1 .text1{ width:30px;}
	.bing_input{ width:40px;}
	</style>
</head>
<body>
<script>
$('#bing1').hide();
</script>
<input id="userinfo" type="hidden" data-uid='{$me.id}' data-name='{$me.user}' data-server='{$me.server}'>
账户：
{volist name="user" id="v"}
<span id="user{$v.id}" data-user="{$v.user}" data-pwd="{$v.pwd}"><a href="{:url('travian/index/index')}/uid/{$v.id}" title="{$v.server}">{$v.user}</a></span>
{/volist}
<input name="settimeout" type="text" class="uk-margin-small-top" value="30" placeholder="循环检测时间（秒）">　 <span class="link" data-link="dorf1.php">村外</span>　<span class="link" data-link="dorf2.php">村内</span>　<span class="link" data-link="build.php?gid=19">兵营</span>　<span class="link" data-link="build.php?gid=20">马厩</span> <span id="msg11"></span>
<div class="uk-grid">
<div class="uk-width-1-1">
村庄：
<div class="uk-grid">
<div id="task_grid">
<ul class="uk-subnav uk-subnav-pill" data-uk-switcher="{connect:'#my-id'}" id="tab1">
{volist name="list" id="v"}
<li><a href="#">{$v.vid}</a></li>
{/volist}
</ul>

<!-- 这是内容项目的容器 -->
<ul id="my-id" class="uk-switcher">
{volist name="list" id="v"}
<table id="v{$v.vid}" width="800" border="0">
  <tr>
    <td colspan="2" valign="top" class="">
<li data-vid="{$v.vid}">
<div data-tid="{$v.task_b.id}"><a target="_blank" href="{:url('attack_list',array('vid'=>$v['vid']))}">抢劫目标</a><br> 
<form name="zaobing">
兵营：<input type="text" class="uk-form-small bing_input" name="build" value="{$v.task_b.build|default=''}">
兵种：<input type="text" class="uk-form-small bing_input" name="t" value="{$v.task_b.t|default=''}">
兵数：<input type="text" class="uk-form-small bing_input" name="ts" value="{$v.task_b.ts}">
马厩：<input type="text" class="uk-form-small bing_input" name="build2" value="{$v.task_b.build2}">
马种：<input type="text" class="uk-form-small bing_input" name="t2" value="{$v.task_b.t2}">
马数：<input type="text" class="uk-form-small bing_input" name="ts2" value="{$v.task_b.ts2}">
<input type="hidden" class="uk-form-small bing_input" name="ft" value="t1">
<input type="hidden" class="uk-form-small bing_input" name="start_time" value="0">
间隔：<input type="text" class="uk-form-small bing_input" name="times" value="{$v.task_b.times}"> <button class="uk-button uk-button-primary" type="button" id="set_zaobing" >设置</button></div> 
</form>
<h3>建：</h3>
<div id="taskbox_build" class="task">
{volist name="v['task']" id="v2"}
<button class="uk-button uk-button-mini" type="button" data-tid="{$v2.id}" data-onclick="addtask({$v.vid},{$v2.build})" onClick="deltask({$v2.id})">{$v2.title}</button> 
{/volist}
</div>
<h3>拆：</h3>
<div id="taskbox_des">
{volist name="v['task_chai']" id="v3"}
<button class="uk-button uk-button-mini" type="button" data-chaiid="{$v3.id}" data-onclick="addtask_chai({$v.vid},{$v3.build})" onClick="deltask_chai({$v3.id})">{$v3.title}</button> 
{/volist}
</div>

</li></td>
  </tr>
  <tr>
    <td id="msg1">
	msg1    </td>
    <td id="msg2">
	msg2	</td>
  </tr>
  <tr>
    <td colspan="2">
	<span><input name="reslevel" type="text" class="uk-margin-small-top" value="10" placeholder="资源田等级"></span>
	<span id="msg3"></span>
	</td>
    </tr>
</table>

{/volist}
</ul>

</div>
</div>	
<div class="uk-panel uk-panel-box"><button class="uk-button uk-button-primary" type="button" onClick="read_viliage(0)">读取村庄</button> 
<button class="uk-button uk-button-primary" type="button" id="start_task" onClick="startBot();dis()">开始任务</button> 
<button class="uk-button uk-button-primary" type="button" id="start_task">停止任务</button>
<button class="uk-button uk-button-primary" type="button" id="test1" >测试按钮</button>
</div></div>
</div>
</body>
<script>
var uid = $('#userinfo').attr('data-uid');
var server = $("#userinfo").attr('data-server'); 
var settimeout;
$('.link').click(function(){
	var linka = $(this).attr('data-link');
	window.open(server+linka);    
	});

function dis(){
	$('#start_task').attr("disabled", true);
	}

function timeb(timeb){
  times = timeb.split(':'); //times倒计时数组（小时，分钟，秒）
  timesec = (times[0]*3600+times[1]*60+times[2]*1); //timesec是倒计时 毫秒
  return timesec;
}

function read_viliage(vid){
    if(vid == 0){var vid = $('#tab1 .uk-active a').text();}
    $.get(server +"dorf1.php?newdid="+vid+'&m='+Math.random(),function(dorf1){
        if($(dorf1).find(".loginTable").length>0){
            $("#message1").html("你还没有登陆游戏，请先登录！");
            $("#msg1").html("你还没有登陆游戏，请先登录！");
        }else{
            var dorfa = [];
            var dorfb = [];
            $(dorf1).find("area").each(function()
            {
                dorfa.push($(this).attr("title"));
                dorfb.push($(this).attr("href"));
            });
  //var dorfa = $(dorf1).find("#logo").html();
  //alert("fff");
            var dorf1html="";
            for(i=0;i<18;i++){
                var jinum;
                var buildid;
                var n1=dorfa[i].indexOf("<div style='color:#FFF'>")+24;　
                var n2=dorfa[i].indexOf('</div>');　　　
                str=dorfa[i].substring(n1,n2);
				str = str.replace('Bosque', "伐木场");
				str = str.replace('Poço de Barro', "黏土矿");
				str = str.replace('Mina de Ferro', "铁矿场");
				str = str.replace('Campo de Cereal', "农场");
				str = str.replace('nível', "等级");
				var n11=str.indexOf("<b>")+3;　
				var n12=str.indexOf("</b>");　
				title = str.substring(n11,n12);
  //ji = dorfa[i].substring(n2-3,n2);
                buildid = i+1;
                jinum='<button class="uk-button uk-button-primary uk-button-small" type="button" onclick=\"addtask(\''+vid+'\',\''+buildid+'\',\''+title+'\');\"> + </button>';
                dorf1html+=str+" "+jinum+"<br/>";
            }
            $("#v"+vid+" #msg1").html(dorf1html);
			var reshtml = '<button class="uk-button uk-button-primary uk-button-small" type="button" onclick=\"addtask(\''+vid+'\',\'0\',\'级资源田按库存\');\">按资源库存升级</button>';
			$("#v"+vid+" #msg3").html(reshtml);
		}
	});
	
	$.get(server +"dorf2.php?newdid="+vid+'&m='+Math.random(),function(dorf2){
        if($(dorf2).find(".loginTable").length>0){
            $("#message1").html("你还没有登陆游戏，请先登录！");
            $("#v"+vid+" #msg1").html("你还没有登陆游戏，请先登录！");
        }else{
            var dorfa = [];
            var dorfb = [];
            $(dorf2).find("area").each(function()
            {
                dorfa.push($(this).attr("title"));
                dorfb.push($(this).attr("href"));
            });
  //var dorfa = $(dorf1).find("#logo").html();
  //alert("fff");
            var dorf2html="";
			var i=0;
            $(dorf2).find("area").each(function(){
                var html,jinum,buildid,title,href,str;
				title = $(this).attr('title');
				str = title;
				str = str.replace('nível', "等级");
				str = str.replace('Zona para construção', "空地");
				str = str.replace('Edifício Principal', "中心大楼");
				str = str.replace('Celeiro', "粮仓");
				str = str.replace('Armazém', "仓库");
				str = str.replace('Ponto de Reunião Militar', "集结点");
				str = str.replace('Palisade', "城墙");
				str = str.replace('Quartel', "兵营");
				str = str.replace('Academia', "研发所");
				str = str.replace('Cavalaria', "马厩");
				str = str.replace('Smithy', "兵工厂");
				str = str.replace('Mercado', "市场");
				str = str.replace('Residência', "行宫");
				str = str.replace('Grain Mill', "磨坊");
				str = str.replace('Sawmill', "木材厂");
				str = str.replace('Brickworks', "砖块厂");
				str = str.replace('Iron Foundry', "铸造厂");
				str = str.replace('Palácio', "皇宫");
				str = str.replace('Horse Drinking Pool', "饮马槽");
				str = str.replace('Tavern', "英雄园");
				str = str.replace('StoneMason', "石匠铺");
				str = str.replace('Oficina', "工场");
				str = str.replace('Tesouraria', "宝库");
				str = str.replace('City Wall', "罗马城墙");
				str = str.replace('Great Warehouse', "大仓库");
				str = str.replace('Great Granary', "大粮仓");
				str = str.replace('Companhia do Comércio', "交易所");
				str = str.replace('Praça de Torneios', "竞技场");
				str = str.replace('Embaixada', "大使馆");
				str = str.replace('Town Hall', "市政厅");
				str = str.replace('World Wonder', "世界奇迹");
				if(str != '空地'){
					//找出等级
					if(str.indexOf("世界奇迹")>=0){
						var n13=str.indexOf("</div> 等级 ")+10;　
					    var n14=str.length;
					}else{
					    var n13=str.indexOf("</b> 等级 ")+8;　
					    var n14=str.indexOf("</div>");　
					}
					jinum = str.substring(n13,n14);
					//找出名称
					var n11=str.indexOf("<b>")+3;　
					var n12=str.indexOf("</b>");　
					title = str.substring(n11,n12);
					//找出bid
					var href = $(this).attr('href');
					var arr_href = href.split('=');
					buildid = arr_href[1];
					html='<button class="uk-button uk-button-primary uk-button-small" type="button" onclick=\"addtask(\''+vid+'\',\''+buildid+'\',\''+title+'\');\"> + </button> <button class="uk-button uk-button-primary uk-button-small" type="button" onclick=\"addtask_chai(\''+vid+'\',\''+buildid+'\',\''+title+'\');\">拆</button>';
				    dorf2html+=title+" 等级 "+jinum+' '+html+"<br/>";
				}else{
					dorf2html+=str+"<br/>";
				};
                
                
				i++;
            });
            $("#v"+vid+" #msg2").html(dorf2html);
		}
	});
}

function deltask(id){
    var btn = $(this);
	$.get("{:url('del_build')}/id/"+id,function(res){
	    if(res.res == 1){
		    //btn.hide();
			$('[data-tid="'+id+'"]').remove();
			//$('#my-id').append('btn------666----------------');
		}else{
		    alert('移除任务失败');
		}
	});
}

function deltask_chai(id){
    var btn = $(this);
	$.get("{:url('del_build_chai')}/id/"+id,function(res){
	    if(res.res == 1){
		    //btn.hide();
			$('[data-chaiid="'+id+'"]').remove();
			//$('#my-id').append('btn------666----------------');
		}else{
		    alert('移除任务失败');
		}
	});
}

function addtask(vid,bid,title){
	var obj = {};var level;
	//alert($('[name="reslevel"]').val());return false;
	if(bid == '0'){
	    level = $('#v'+vid+' [name="reslevel"]').val();
		title = level + title;
	}else{
	    level = '0';
	}
	obj['title'] = title;
	obj['level'] = level;
	$.get("{:url('add_build')}/vid/"+vid+"/bid/"+bid,obj,function(res){
	    if(res.res == 1){
		var btn = ' <button class="uk-button uk-button-mini" type="button" data-tid="'+res.id+'" data-onclick="addtask('+res.id+','+bid+')" onclick="deltask('+res.id+')">'+title+'</button>';
		    $('li[data-vid="'+vid+'"] #taskbox_build').append(btn);
			//$('#my-id').append('btn------666----------------');
		}else{
		    alert('添加任务失败');
		}
	});
}

function addtask_chai(vid,bid,title){
	var obj = {};var level;
	obj['title'] = title;
	//obj['level'] = level;
	$.get("{:url('add_build_chai')}/vid/"+vid+"/bid/"+bid,obj,function(res){
	    if(res.res == 1){
		var btn = ' <button class="uk-button uk-button-mini" type="button" data-chaiid="'+res.id+'" data-onclick="addtask_chai('+res.id+','+bid+')" onclick="deltask_chai('+res.id+')">'+title+'</button>';
		    $('li[data-vid="'+vid+'"] #taskbox_des').append(btn);
			//$('#my-id').append('btn------666----------------');
		}else{
		    alert('添加任务失败');
		}
	});
}

//造兵任务检测
function startBot2(){
    $.get("{:url('get_task2')}/uid/{$uid}",function(data){
		if($(data).length>0){
	    $.each(data,function(i,son){
			//alert(i);
		    var arr = [];
			arr[0] = son.id;
			arr[1] = son.vid;
			arr[2] = son.ft;
			arr[3] = son.build;
			arr[4] = son.t;
			arr[5] = son.ts;
			arr[6] = son.build2;
			arr[7] = son.t2;
			arr[8] = son.ts2;
			arr[9] = son.times;
			//arr[8] = son.start_time;
			var str = arr.toString();
			setTimeout('zao2("'+str+'")',500);
		});
		}else{
			//startBot3();
		}
		setTimeout('startBot3()',1000);
	});
}

//开始造兵
function zao2(str){
			var arr = str.split(",");
		    var  id    = arr[0];
		    var vid    = arr[1];
			var ft     = arr[2];
			var build  = arr[3];
			var t      = arr[4];
			var ts     = arr[5];
			var url = server + "build.php?newdid="+vid;
			/*
			var build2 = arr[6];
			var t2     = arr[7];
			var ts2    = arr[8];
			*/
			var obj = {};
			obj['id'] = build;
			obj['ft'] = ft;
			obj[t] = ts;
			if(ts*1>0){
			$.ajax({
			    url: url,
			    type: 'post',
			    cache:false, 
			    data: obj,
			    dataType: 'html',
			    success: function(data1) {
			}
			});
			}
	setTimeout('zao2b("'+str+'")',1000);		
}

//开始造马（如果有）
function zao2b(str){
			var arr = str.split(",");
		    var  id    = arr[0];
		    var vid    = arr[1];
			var ft     = arr[2];
			var build2 = arr[6];
			var t2     = arr[7];
			var ts2    = arr[8];
			var times  = arr[9];
			var url = server + "build.php?newdid="+vid;
			var obj = {};
			obj['id'] = build2;
			obj['ft'] = ft;
			obj[t2] = ts2;
			if(ts2*1>0){
			$.ajax({
			    url: url,
			    type: 'post',
			    cache:false, 
			    data: obj,
			    dataType: 'html',
			    success: function(data1) {
			}
			});
			}
			$.get("{:url('set_task2')}/id/"+id+"/times/"+times,function(data){});
		//setTimeout('startBot3()',1000);	
}

//抢夺任务检测
function startBot3(){
    $.ajax({
			        url: "{:url('get_task3')}/uid/{$uid}",
			        type: 'get',
			        cache:false, 
					async : false,//
			        data: '',
			        dataType: 'json',
			        success: function(data) {
        //$.get("{:url('get_task3')}/uid/{$uid}",function(data){
		//如果有目标就是1
		//var status = 0;
		//var iii = 0;var status;
		//if($(data).length>0){
	    $.each(data,function(i,son){
		/*
		iii++;
		if(iii>=$(data).length){
		    status = 0;
		}
		*/
		//历编每个目标
			var arr = [];
			arr[0] = son.id;
			arr[1] = son.vid;
			arr[2] = son.x;
			arr[3] = son.y;
			arr[4] = son.t;
			arr[5] = son.times;
			//arr[6] = status;
			//arr[8] = son.start_time;
			var str = arr.toString();
			setTimeout('zao3("'+str+'")',800);
		});
		
		//}else{
		    //sleep_b();
		//}
		}
	});
	sleep_b();
}

//开始攻击
function zao3(str){
	            var arr1   = str.split(",");
				var  id    = arr1[0];
	    	    var vid    = arr1[1];
	    	    var x      = arr1[2];
	    	    var y      = arr1[3];
	    	    var t      = arr1[4];
	    	    var times  = arr1[5];
				//var status = arr1[6];
				
				var arr = t.split("|");
				var obj = {};var obj2 = {};
				if(arr[0]>0){obj['t1']=arr[0];obj2['t1']=arr[0];}
				if(arr[1]>0){obj['t2']=arr[1];obj2['t2']=arr[1];}
				if(arr[2]>0){obj['t3']=arr[2];obj2['t3']=arr[2];}
				if(arr[3]>0){obj['t4']=arr[3];obj2['t4']=arr[3];}
				if(arr[4]>0){obj['t5']=arr[4];obj2['t5']=arr[4];}
				if(arr[5]>0){obj['t6']=arr[5];obj2['t6']=arr[5];}
				if(arr[6]>0){obj['t7']=arr[6];obj2['t7']=arr[6];}
				if(arr[7]>0){obj['t8']=arr[7];obj2['t8']=arr[7];}
				if(arr[8]>0){obj['t9']=arr[8];obj2['t9']=arr[8];}
				if(arr[9]>0){obj['t10']=arr[9];obj2['t10']=arr[9];}
				if(arr[10]>0){obj['t11']=arr[10];obj2['t11']=arr[10];}
				obj['x'] = x;
				obj['y'] = y;
				obj['c'] = 4;
				obj['s1'] = 'ok';
				$.ajax({
			        url: server +"a2b.php"+"?newdid="+vid,
			        type: 'post',
			        cache:false, 
					async : false,//
			        data: obj,
			        dataType: 'html',
			        success: function(a2b) {
					if($(a2b).find('.troop_details').length>0){
					    //成功到发兵确认页面
						obj2['id'] = '39';
						obj2['timestamp'] = $(a2b).find('[name="timestamp"]').val();
						obj2['timestamp_checksum'] = $(a2b).find('[name="timestamp_checksum"]').val();
						obj2['ckey'] = $(a2b).find('[name="ckey"]').val();
						obj2['a'] = $(a2b).find('[name="a"]').val();
						obj2['c'] = 3;
						obj2['s1'] = 'ok';
						$.ajax({
						    url: server +"a2b.php"+"?newdid="+vid,
						    type: 'post',
						    cache:false, 
							async : false,//
						    data: obj2,
						    dataType: 'html',
						    success: function(a2b2) {
						        if($(a2b2).find('img.g16').length>0){
						        //发兵成功
						            $.get("{:url('set_task3')}/id/"+id+"/times/"+times,function(data){
									    
									});
								}
						    }
						});
					}
					}
			    });
		/*
		if(status = 0){
		    sleep_b();
		}
		*/
}

function login_sleep(){
    setTimeout('startBot()',600);
}

function login(){
    var obj = {};
    obj['user'] = $('#user{$uid}').attr('data-user');
    obj['pw']   = $('#user{$uid}').attr('data-pwd');
    obj['ft']   = 'a4';
    obj['s2']   = 'go';
	$.ajax({
        url: server +"login.php",
        type: 'post',
        cache:false, 
        async : false,//
        data: obj,
        dataType: 'html',
        success: function(login) {
            if($('login').find('.playerName').length>0){
			    startBot();
			}else{
			    login_sleep();
			}
        }
    });
}

//建筑任务检测
function startBot(){
    $.get("{:url('get_task')}/uid/{$uid}",function(data){
		//if($(data).length>0){
	    $.each(data,function(i,son){
			//alert(i);
		    var arr = [];
			arr[0] = son.id;
			arr[1] = son.vid;
			arr[2] = son.build;
			arr[3] = son.level;
			arr[4] = '';
			var resource = [];
			var href;
			var build;
			var dorf1;
			var name = [];
			name[0] = 'Bosque';
			name[1] = 'Poço de Barro';
			name[2] = 'Mina de Ferro';
			name[3] = 'Campo de Cereal';
			resource[0] = "<div style='color:\\#FFF'><b>"+name[0]+"</b>";
			resource[1] = "<div style='color:\\#FFF'><b>"+name[1]+"</b>";
			resource[2] = "<div style='color:\\#FFF'><b>"+name[2]+"</b>";
			resource[3] = "<div style='color:\\#FFF'><b>"+name[3]+"</b>";
			
			var vid = son.vid;
				$.ajax({
				    url: server +"dorf1.php?newdid="+vid+'&m='+Math.random(),
				    type: 'get',
				    cache:false, 
				    async : false,//
				    data: '',
				    dataType: 'html',
				    success: function(dorf1) {
					    //dorf1 = dorf1a;
						
			//P田
			if($(dorf1).find(".loginTable").length>0){
			    //检测到未登录
				login();
				return false;
			}
			//如果level字段大于0，就是按库存P田，到等级level级。
			if(arr[3]*1>0){
			
			//重写
			var arr_tian = [];
			var i=0;
			var l1,l2,l3,l4;
			$(dorf1).find('map area').each(function(){
				
				var str = $(this).attr('title');
				var n11=str.indexOf("</b> nível ")+11;　
				var n12=str.indexOf("</div>");　
				var num2 = str.substring(n11,n12)*1;
				var href = $(this).attr('href');
				//
				var type = $(str).find('b').text();
			    i++;
				if(num2<son.level*1){
				    //arr_tian.push($(this));
				    if($(this).attr('title').indexOf("<div style='color:#FFF'><b>"+name[0]+"</b>")>=0){l1 = 'you';}
				    if($(this).attr('title').indexOf("<div style='color:#FFF'><b>"+name[1]+"</b>")>=0){l2 = 'you';}
				    if($(this).attr('title').indexOf("<div style='color:#FFF'><b>"+name[2]+"</b>")>=0){l3 = 'you';}
				    if($(this).attr('title').indexOf("<div style='color:#FFF'><b>"+name[3]+"</b>")>=0){l4 = 'you';}
				}
			});
			
			    //看库存
				var arr_num = [];var num;
				    $(dorf1).find('.stockBarButton .value').each(function(){
				    num = $(this).text()*1;
				    arr_num.push(num);
				});
				//如果没有 you ，也就是次种资源田全部P到指定等级，则此种资源田库存暂设最大数999999999
				if(l1 != 'you'){arr_num[0] = 999999999;}
				if(l2 != 'you'){arr_num[1] = 999999999;}
				if(l3 != 'you'){arr_num[2] = 999999999;}
				if(l4 != 'you'){arr_num[3] = 999999999;}
				//第几个元素的资源库存最少，然后n就是这个上面定义的resource字符串（<div style='color:\\#FFF'><b>Bosque</b>）
			    //重写  接下
						//第几个元素的资源库存最少，然后n就是这个上面定义的resource字符串（<div style='color:\\#FFF'><b>Bosque</b>）
						var n = resource[arr_num.indexOf(Math.min.apply(Math, arr_num))];
						var arr_num2 = [];
						var kk = 1;
						$(dorf1).find('map area[title*="'+n+'"]').each(function(){
						    var str = $(this).attr('title');
						    var n11=str.indexOf("</b> nível ")+11;　
						    var n12=str.indexOf("</div>");　
						    var num2 = str.substring(n11,n12)*1;
							arr_num2.push(num2);
						});
					//找到最小等级资源田ID
					    var n2 = arr_num2.indexOf(Math.min.apply(Math, arr_num2));
						href = $(dorf1).find('map area[title*="'+n+'"]').eq(n2).attr('href');
						var arrr = href.split('=');
						build = arrr[1];
					//
						if(Math.min.apply(Math, arr_num2)<son.level*1){
						console.log(vid+' 库存：'+arr_num+' 类型：'+n+' '+' 库存最少资源田的最小等级那个：'+Math.min.apply(Math, arr_num2)+' 指定等级：'+son.level);
						//如果最小的指定类型田小于等于设定目标等级，
						    
							//nono是不删任务，只更新下次时间
			            arr[4] = 'nono';
						}else{
						var vname = $(dorf1).find('#sidebarBoxVillagelist li.active .name').text();
						console.log('nono2了，村庄：'+son.vid+' '+vname+' 建筑：'+href+' 目标等级：'+Math.min.apply(Math, arr_num2)+' 指定上限等级：'+son.level);
							//否则跳过，并删除任务
							//nono2 是直接删除任务
							arr[4] = 'nono2';
						}
				arr[2] = build;
				var str = arr.toString();
				setTimeout('zao("'+str+'")',500);
			}else{
			var str = arr.toString();
			setTimeout('zao("'+str+'")',500);
			}
			//P田
						
						
					}
				});
		});
		//}else{

		//}
		
		
	});
	setTimeout('startBot_chai()',1000);
}


						//console.log('村子：'+son.vid+' 目标类型：'+n+' 等级分别是：'+kk+':'+arr_num2.toString());
						//历编所有资源田等级   暂时没使用
						//如果使用就把下面的  if(Math.min.apply(Math, arr_num2)<son.level*1){ 其中的arr_num2改为arr_num3
					/*	var arr_num3 = [];
						$(dorf1).find('map area').each(function(){
						    var str = $(this).attr('title');
						    var n11=str.indexOf("</b> nível ")+11;　
						    var n12=str.indexOf("</div>");　
						    var num3 = str.substring(n11,n12)*1;
						    arr_num3.push(num3);
						});
					*/	//历编所有资源田等级 end

function sleep_a(){
	setTimeout('startBot2()',1000);
}

function sleep_b(){
    settimeout = $('[name="settimeout"]').val();
	setTimeout('startBot()',settimeout*1000);
}

//开始建筑
function zao(str){
			var arr = str.split(",");
		    var  id = arr[0];
		    var vid = arr[1];
			var bid = arr[2];
			var nono = arr[4];
			//nono2是最低库存的田种已超过 设定目标等级，所以删除任务
			if(nono == 'nono2'){
			    $.get("{:url('set_task')}/vid/"+vid+'/uid/'+uid+'/id/'+id+'/inctime/1/nono/'+nono,function(data){
				});
				$("[data-tid='"+id+"']").remove();
			}else{
			//$.get(server +"build.php?id="+bid+"&newdid="+vid+'&m='+Math.random(),function(build){
			
			
			//----
			$.ajax({
				    url: server +"build.php?id="+bid+"&newdid="+vid+'&m='+Math.random(),
				    type: 'get',
				    cache:false, 
				    async : false,//
				    data: '',
				    dataType: 'html',
				    success: function(build) {
					    //如果是最高等级
				if($(build).find('span.none:contains("The building is at the maximum level.")').length>0){
				    //window.wxc.xcConfirm(build);
					nono = 'nono2';
					$.get("{:url('set_task')}/vid/"+vid+'/uid/'+uid+'/id/'+id+'/inctime/2/nono/'+nono,function(data){
				    });
					$("[data-tid='"+id+"']").remove();
				}else{
				    if($(build).find('.small').length>0){
				        var click_url = $(build).find('.small').attr('onclick');
				        var arr = click_url.split("'");
				        var links = arr[1];
						var clocks = $(build).find('.clocks').html();
						var n11=clocks.length-8;　
				        var n12=clocks.length;　
				        var text = clocks.substring(n11,n12);
						var timeba = timeb(text);
	/////////////////改为AJAX
						$.ajax({
				    url: server+links+"&newdid="+vid,
				    type: 'get',
				    cache:false, 
				    async : false,//
				    data: '',
				    dataType: 'html',
				    success: function(build2) {
					    //如果开始了
				        if($(build2).find('.buildDuration span').length>0){
				                //var timess = $(build2).find('.buildDuration span').text();
				                //var timeba = timeb(timess);
				                $.get("{:url('set_task')}/vid/"+vid+'/uid/'+uid+'/id/'+id+'/inctime/'+timeba+'/nono/'+nono,function(data){
				                    if(data == 'ok'){
				                    //更新任务成功
				                        if(nono != 'nono'){$("[data-tid='"+id+"']").remove();}
				                        read_viliage(vid);
				                    }else{
				                        //alert('更新失败');
				                    }
							    });
					        }else{
					             //alert('建造失败');
					        }
	                }
	            }); 
		/////////////////改为AJAX end
			    	}else{
				    //alert('不能建造');
				    }
				}
	                }
	            }); 
			//-------
			}
			
		//sleep_a();
}

function startBot_chai(){
    $.ajax({
			        url: "{:url('get_task_chai')}/uid/{$uid}",
			        type: 'get',
			        cache:false, 
					async : false,//
			        data: '',
			        dataType: 'json',
			        success: function(data) {
	    $.each(data,function(i,son){
		//历编每个任务
			var arr = [];
			arr[0] = son.id;
			arr[1] = son.vid;
			arr[2] = son.build;
			arr[3] = son.title;
			var str = arr.toString();
			setTimeout('zao_chai("'+str+'")',800);
		});
		}
	});
	setTimeout('startBot2()',1000);
}

//开始拆
function zao_chai(str){
    var arr = str.split(",");
    var  id = arr[0];
    var vid = arr[1];
    var bid = arr[2];
	$.ajax({
	    url: server +"build.php?gid=15&newdid="+vid,
	    type: 'get',
	    cache:false, 
	    async : false,//
	    data: '',
	    dataType: 'html',
	    success: function(build_26) {
		    var time1;
			var timeba;
			//如果有select框
			if($(build_26).find('.dropdown').length>0){
		    //如果存在这个建筑
			//alert('这个id的select数量:'+$(build_26).find('.dropdown option[value="'+bid+'"]').length);
			//alert('.dropdown option[value="'+bid+'"]');
			//alert('这个id的select数量:'+$(build_26).find('.dropdown option[value="'+bid+'"]').length);
	        if($(build_26).find('.dropdown option[value="'+bid+'"]').length>0){
			    var form = $(build_26).find('form').eq(0);
				var ac = form.attr('action');
				var obj = {};
				var str = $(build_26).find('.dropdown option[value="'+bid+'"]').text();
				var n11=str.indexOf("(lvl ")+5;　
				var n12=str.indexOf(")");　
				var level = str.substring(n11,n12)*1;
                obj['type'] = bid;
				//开始拆
				//alert(server + ac);
				$.ajax({
				    url: server + ac,
				    type: 'post',
				    cache:false, 
				    async : false,//
				    data: obj,
				    dataType: 'html',
				    success: function(build_26_2) {
					    //如果开始拆了
				        if($(build_26_2).find('#timer1').length>0){
				            time1 = $(build_26_2).find('#build span').text();
				            timeba = timeb(time1);
							var nono = 'nono';
							if(level<=1){nono = 'nono2';timeba=1;$("[data-caiid='"+id+"']").remove();}
				            $.get("{:url('set_task_chai')}/vid/"+vid+'/uid/'+uid+'/id/'+id+'/inctime/'+timeba+'/nono/nono',function(data){
				                //read_viliage();
				            });
						
				        }else{
						//任务失败
						    
				        }
	                }
	            });
			}else{
			//如果不存在此建筑
			    $.get("{:url('set_task_chai')}/vid/"+vid+'/uid/'+uid+'/id/'+id+'/inctime/1/nono/nono2',function(data){
				i$("[data-chaiid='"+id+"']").remove();
				    //read_viliage();
				});
			}
			}
	    }
	});
	
}

/*
$('#read_task1').click(function(){
$('#task_grid').html('');
    var account = $("[name='account']").val();
    $.get("{:url('get_viliage')}/account/"+account,function(data){
	    var vtitle = '';
	    var viliage = '';var vcontent = '';var ii=0;kk=0;
		vtitle   += '<ul class="uk-subnav uk-subnav-pill" data-uk-switcher="{connect:\'#subnav-pill-content-1\'}">';
		vcontent += '<ul id="subnav-pill-content-1" class="uk-switcher">';
		$.each(data,function(i,n){
		    var task = '';var vhtml2 = '';ii++;
			if(ii==1){vtitle   += '<li class=""><a href="#">'+n['vid']+'</a></li>';}else{vtitle   += '<li aria-expanded="false" class=""><a href="#">'+n['vid']+'</a></li>';}
			vcontent += '<li>aaaaaaa'+ii;
		    $.get("{:url('get_task')}/vid/"+n['vid'],'',function(data2){
	            $.each(data2,function(i2,n2){
	                //task += n2['build'];
	                //task += '<br>';
					task +='<button class="uk-button uk-button-primary" type="button" onclick=\'addtask('+n['vid']+'|'+n2['build']+')\'>'+n2['title']+'/'+n2['level']+'</button><br>';
	            });*/
		    /*
			viliage += '<div class="uk-width-1-6">';
			viliage += n['vid']+' ：'+n['date']+'<br>';
			viliage += task;
			viliage += '</div>';
			$('#task_grid').append(viliage);
			*/
			/*
	        });
			vcontent += task;
			vcontent += '</li>';
		});
		vtitle   += '</ul>';
		vcontent += '</ul>';
		$('#task_grid').html(vtitle);
		$('#task_grid').append(vcontent);
	});
});
*/
function ajax(url,type){
    $.ajax({
		url: url,
		type: 'get',
		cache:false, 
		//data: obj,
		dataType: type,
		success: function(data) {
		    return data;
	    }
	 });
}



function go1(){ //检测所有村庄，下一次建筑时间是否到。
	var account = $("[name='account']").val();
	var server = $("[name='account']").find("option:selected").attr('data-server');
	$.get("{:url('get_viliage')}/account/"+account,'',function(data){
	    var viliage = '';var start_build_time;
		$.each(data,function(i,n){
		    start_build_time = n['start_build_time'];
		    var task = '';$i2 = 0;
		    $.get("{:url('get_taskfirst')}/vid/"+n['vid'],'',function(data2){
				if(data2.build){
				    var build = data2.build;
					//console.log(data);  
					if(n['start'] == 'ok'){
					    var drof = server+'/build.php?id='+data2.build;
					    /*
						var rs = ajax(drof,'html');
						alert(rs);
						*/
						$.ajax({
							url: drof,
							type: 'get',
							cache:false, 
							dataType: 'html',
							success: function(rs) {
								var click_url = $(rs).find('.small').attr('onclick');
								if(typeof(click_url)!="undefined"){
								var arr = click_url.split('\'');
								    //可建造
									var str;
									str = n['vid']+'|';//村庄数据库ID
									str += arr[1]+'|';//建筑升级链接
									str +=  data2.id;//建筑数据库ID
									setTimeout('go2("'+str+'")',3230);
									return false;
								}else{
								    //不能建造
									
								}
							}
						});
					}
				}
	        });
		});
		
	});
}

function go2(str){
/*
console.log(arg);
return;
alert(arg[0]+'-1');alert(arg[1]+'-2');alert(arg[2]+'-3');*/
var arg = str.split('|');

     var server = $("[name='account']").find("option:selected").attr('data-server');
	 alert(server+'/'+arg[1]);
	 var uid = $("[name='account']").val();
     $.get(server+'/'+arg[1],function(data){
	     var time = $(data).find('span[id^="time"]').html();
		 var s = time_to_s(time);
		 $.get("{:url('set_build_time')}/uid/"+uid+"/vid/"+arg[0]+"/time/"+s+"/bid/"+arg[2],function(data){
		 var aa;
		 });
	 });
}

function time_to_s(time){
    var arr = time.split(':');
	var s = arr[0]*60*60 + arr[1]*60 + arr[2];
    return s
}

$('#stop_task').click(function(){
    window.clearInterval(t1);
});

$('#test1').click(function(){
    /*
	var arr_num = [];var num;
    $('body').find('.stockBarButton .value').each(function(){
    num = $(this).text()*1;
    arr_num.push(num);
	
	});
	alert(arr_num.indexOf(Math.min.apply(Math, arr_num)));
	*/
	
	
	/*
	var resource = [];
	var href;
	resource[0] = "<div style='color:\\#FFF'><b>Bosque</b>";
	resource[1] = "<div style='color:\\#FFF'><b>Poço de Barro</b>";
	resource[2] = "<div style='color:\\#FFF'><b>Mina de Ferro</b>";
	resource[3] = "<div style='color:\\#FFF'><b>Campo de Cereal</b>";
	var arr_num = [];var num;
	$('.stockBarButton .value').each(function(){
	    num = $(this).text()*1;
	    arr_num.push(num);
		//alert(num);
	});
	var n = resource[arr_num.indexOf(Math.min.apply(Math, arr_num))];
	//alert(n);
	//alert($('map area[title*="'+n+'"]').length);
	var arr_num2 = [];
	$('map area[title*="'+n+'"]').each(function(){
		var str = $(this).attr('title');
		var n11=str.indexOf("</b> nível ")+11;　
		var n12=str.indexOf("</div>");　
		var num2 = str.substring(n11,n12)*1;
		arr_num2.push(num2);
	});
	if(Math.min.apply(Math, arr_num2)<15){
		//如果最小的指定类型田大于等于设定目标等级，则跳过，并删除任务
	    var n2 = arr_num2.indexOf(Math.min.apply(Math, arr_num2));
		href = $('map area[title*="'+n+'"]:eq('+n2+')').attr('href');
	}
	*/
	
	
	var aaaa = $('span.none:contains("The building is at the maximum level.")').length;
	alert(aaaa);
});

$('#test2').click(function(){
    $('#bing1').show();
});

$('#clsBtn').click(function(){
    //$(this).parent().parent().parent().hide();
	$('#bing1').hide();
});

$('#bing_btn').click(function(){
	var btn = $(this);
	btn.attr("disabled", true);
	var obj = $("#form1").serialize();
	var vid = $('#tab1 .uk-active a').text();
    $.ajax({
        url: "{:url('add_attack')}/vid/"+vid,
        type: 'post',
        cache: false, 
		data: obj,
        dataType: 'json',
        success: function(rs) {
            alert(rs.b);
	    }
	});
});

$('#set_zaobing').click(function(){
	//var btn = $(this);
	//btn.attr("disabled", true);
	var obj = $(this).parent().serialize();
	var vid = $('#tab1 .uk-active a').text();
    $.ajax({
        url: "{:url('set_zaobing')}/vid/"+vid,
        type: 'post',
        cache: false, 
		data: obj,
        dataType: 'json',
        success: function(rs) {
            if(rs == '1'){
			    window.wxc.xcConfirm('更新成功');
			}
	    }
	});
});
</script>
</html>